//
//  ViewController.h
//  GTShareSDK
//
//  Created by yate1996 on 15/7/17.
//  Copyright (c) 2015年 yate1996. All rights reserved.
//

#import "ViewController.h"
#import "Utils.h"
@interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
/**
 *  分享按钮
 */
@property (strong, nonatomic) UIButton *shareButton;
/**
 *  图片显示器
 */
@property (strong, nonatomic) UIImageView *imageView;
/**
 *  图片选择器
 */
@property (strong, nonatomic) UIImagePickerController *imagePicker;
/**
 *  加载图片按钮
 */
@property (strong, nonatomic) UIButton *addImageButton;
/**
 *  选中的图片
 */
@property (strong, nonatomic) UIImage *selectImage;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //分享按钮
    UIButton *shareButton = [[UIButton alloc]initWithFrame:CGRectMake(20, 130, 50, 44)];
    shareButton.backgroundColor = [UIColor orangeColor];
    [shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [self.view addSubview:shareButton];
    self.shareButton = shareButton;
    [self.shareButton addTarget:self action:@selector(sendShare:) forControlEvents:UIControlEventTouchUpInside];
    
    //添加相片按钮
    UIButton *addImageButton = [[UIButton alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width * 0.7, 130, 90, 44)];
    addImageButton.backgroundColor = [UIColor orangeColor];
    [addImageButton setTitle:@"添加图片" forState:UIControlStateNormal];
    [self.view addSubview:addImageButton];
    self.addImageButton = addImageButton;
    [self.addImageButton addTarget:self action:@selector(addImage) forControlEvents:UIControlEventTouchUpInside];
    
    
    _selectImage = [UIImage imageNamed:@"shareImg"];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 300, 320, 250)];
    [self.view addSubview:imageView];
    
  
}

-(void)sendShare:(UIButton *)button
{
    Utils *utils = [[Utils alloc]init];
   
    [utils showShareActionSheet:button withShareParamsByText:@"这是系统默认的分享内容测试" images:@[self.selectImage] url:[NSURL URLWithString:@"www.baidu.com"] title:@"分享标题" type:SSDKContentTypeText];
}

/**
 *  添加图片菜单
 *
 *
 */
- (void)addImage{
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
    imagePicker.view.backgroundColor = [UIColor orangeColor];
    UIImagePickerControllerSourceType sourcheType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    imagePicker.sourceType = sourcheType;
    imagePicker.delegate = self;
    imagePicker.allowsEditing = YES;
    [self presentViewController:imagePicker animated:YES completion:nil];
    self.imagePicker = imagePicker;
}

/**
 *  选择图片完成
 *
 *  @param info中包含选择的图片
 */
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    _selectImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    UIImageView *iview = [[UIImageView alloc] initWithImage:_selectImage];
    iview.frame = CGRectMake(0, 400, 300, 200);
    
    [self.view addSubview:iview];
    self.imageView = iview;
    [self dismissViewControllerAnimated:YES completion:nil];
    
}
@end
